package api

import (
	"fmt"
	. "helloGo/config"

	"github.com/gin-gonic/gin"
)

type Demo struct {
	Name     string `gorm:"not_null"`
	Password string `gorm:"not_null"`
}

// @Summary Add a new pet to the store
// @Description get string by ID
// @Success 200 {string} string	"ok"
// @Failure 400 {string} string "We need ID!!"
// @Router /hello [get]
func HelloWorld(c *gin.Context) {
	add()
	demos := get()
	destroy(1)
	c.JSON(200, gin.H{
		"status":  "posted",
		"message": "message",
		"nick":    demos,
	})
}

func add() {
	demo := &Demo{Name: "zhangsan", Password: "zhangsan"}

	if err := Db.Create(demo).Error; err != nil {
		fmt.Println("报错了")
		fmt.Println(err)
	}

}

func get() []Demo {
	var demos []Demo
	Db.Find(&demos)
	return demos
}

//删除数据
//接收者
func destroy(id int64) {
	var demo Demo
	d := Db.Where("id = ?", id).Delete(&demo)
	fmt.Println(d)
}
